#ifndef SEARCH_COMMAND_IN_H_
#define SEARCH_COMMAND_IN_H_
#include "command.h"

#pragma pack(1)
namespace Cmd
{
        namespace Search 
        {
                //  cmd declaration
                enum {
                        CMDIN_LOGIN             = 0x0050,       // 登录SearchServer验证指令
                        CMDIN_FORWARD           = 0x0051,	// 转发的指令
                        CMDIN_SESSION           = 0x0052,	// 与SessionServer交互的指令
                };
                enum { //CMDIN_LOGIN
                        SCMDIN_LOGIN                            = 0x0001,       // 请求登录SearchServer
                        SCMDIN_LOGIN_RESPONCE                   = 0x0002,	// 登录SearchServer返回
                };
                enum { //CMDIN_FORWARD
                        SCMDIN_FORWARD_SEARCH                   = 0x0001,       // 转发到SearchServer的指令
                        SCMDIN_FORWARD_USER                     = 0x0002,	// SearchServer转发指令给用户
                };
                enum { //CMDIN_SESSION
                        SCMDIN_SESSION_REQ_USER_BY_USERNAME     = 0x0001,
                        SCMDIN_SESSION_REQ_USER_BY_USERNAME_RES = 0x0002,
                        SCMDIN_SESSION_REQ_USER_BY_NICKNAME     = 0x0003,
                        SCMDIN_SESSION_REQ_USER_BY_NICKNAME_RES = 0x0004,
                };

                //	cmd definition
                struct stLoginCmd:t_NullCmd
                {
                        stLoginCmd():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN)
                        {
                                dest_type_ = SEARCHSERVER;
                                server_type_ = 0;
                                server_id_ = 0;
                        }
                        WORD dest_type_;
                        WORD server_type_;
                        DWORD server_id_;
                };
                struct stLoginResponce:t_NullCmd
                {
                        stLoginResponce():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN_RESPONCE)
                        {
                        }
                };

                struct stForwardSearch:
                        t_NullCmd
                {
                        stForwardSearch():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD_SEARCH)
                        {
                                user_id_ = 0;
                                size_ = 0;
                        }
                        DWORD user_id_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize() const
                        {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };
                struct stForwardUser:
                        t_NullCmd
                {
                        stForwardUser():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD_USER)
                        {
                                user_id_ = 0;
                                size_ = 0;
                        }
                        DWORD user_id_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize() const
                        {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };
                struct stSessionReqUserByUserName:
                        t_NullCmd
                {
                        stSessionReqUserByUserName():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_REQ_USER_BY_USERNAME)
                        {
                                user_id_ = 0;
                                bzero(user_name_, sizeof(user_name_));
                                page_ = 0;
                                num_per_page_ = 10;
                        }
                        DWORD user_id_;
                        BYTE user_name_[MAX_ACCOUNT_SIZE+1];
                        WORD page_;
                        WORD num_per_page_;
                };
                struct stSessionReqUserByUserNameRes:
                        t_NullCmd
                {
                        stSessionReqUserByUserNameRes():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_REQ_USER_BY_USERNAME_RES)
                        {
                                user_id_ = 0;
                                size_ = 0;
                                page_ = 0;
                                num_per_page_ = 10;
                        }
                        DWORD user_id_;
                        WORD size_;
                        WORD page_;
                        WORD num_per_page_;
                        BYTE finish_; //0-not finish,1-finish
                        struct {   
                                DWORD user_id_;
                                char user_name_[MAX_ACCOUNT_SIZE+1];
                                char nick_name_[MAX_NAME_SIZE+1];
                        } list_[0];
                        DWORD getSize() 
                        {   
                                return sizeof(*this)+size_*sizeof(list_[0]);
                        }
                };
                struct stSessionReqUserByNickName:
                        t_NullCmd
                {
                        stSessionReqUserByNickName():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_REQ_USER_BY_NICKNAME)
                        {
                                user_id_ = 0;
                                bzero(nick_name_, sizeof(nick_name_));
                                page_ = 0;
                                num_per_page_ = 10;
                        }
                        DWORD user_id_;
                        BYTE nick_name_[MAX_NAME_SIZE+1];
                        WORD page_;
                        WORD num_per_page_;
                };
                struct stSessionReqUserByNickNameRes:
                        t_NullCmd
                {
                        stSessionReqUserByNickNameRes():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_REQ_USER_BY_NICKNAME_RES)
                        {
                                user_id_ = 0;
                                size_ = 0;
                                page_ = 0;
                                num_per_page_ = 10;
                        }
                        DWORD user_id_;
                        WORD size_;
                        WORD page_;
                        WORD num_per_page_;
                        BYTE finish_; //0-not finish,1-finish
                        struct {   
                                DWORD user_id_;
                                char user_name_[MAX_ACCOUNT_SIZE+1];
                                char nick_name_[MAX_NAME_SIZE+1];
                        } list_[0];
                        DWORD getSize() 
                        {   
                                return sizeof(*this)+size_*sizeof(list_[0]);
                        }
                };

        }; //namespace Search
}; //namespace Cmd
#pragma pack() //pack(1)

#endif //SEARCH_COMMAND_H_
